const Controller = require('../core/base_controller');
const _ = require('lodash')

class AppController extends Controller {
    async remove() {
        const { app } = this
        // app.table('').deleteBy({
        //     customer_id: this.param.customer_id
        // })
    }

    /**
     * 保存批次信息
     * 
     * @memberof AppController
     */
    async save() {
        const { customer_id, remark } = this.param
        const { app, service: { batch } } = this
        //保存批次
        let batchInfo = await batch.save(this.param)
        this.success(batchInfo)
    }

    /**
     * 发布报价
     * 
     * @memberof AppController
     */
    async publish() {
        const { customer_id, remark } = this.param
        const { app, service: { batch } } = this
        //保存批次
        let batchInfo = await batch.publish(this.param)
        this.success(batchInfo)
    }

    /**
     * 分页查询
     * 
     * @memberof AppController
     */
    async page() {
        const { app, service: { batch } } = this
        let ret = await batch.page(this.param)
        this.success(ret)
    }

    /**
     * 获取批次以及批次里的产品数据
     * 
     * @memberof AppController
     */
    async getBatchAndProduct() {
        const { app, service: { batch } } = this

        const { id , copy_id } = this.param 

        let ret = await batch.getBatchAndProduct({ id: copy_id || id })

        //如果是复制的版本，则清空当前数据的batch_id
        if(ret && copy_id) {
            ret.batch_id = null
            for(var product of ret.batch_products) {
                product.batch_id = null
            }
        }

        this.success(ret)
    }

}
module.exports = AppController;
